package com.xtx.air.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.xtx.air.web.commons.DatasCache;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.interceptor.SessionAware;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class BaseAction extends ActionSupport implements SessionAware {
	private static final long serialVersionUID = 7832295150101890553L;
	protected Log logger = LogFactory.getLog(this.getClass());
	protected Map session;
	private String operName;

	public void setSession(Map session) {
		this.session = session;
	}

	public String getOperName() {
		Subject subject = SecurityUtils.getSubject();
		if (subject.isAuthenticated()) {
			operName = subject.getPrincipal().toString();
		} else {
			operName = "游客";
		}
		return operName;
	}
    
	public List<String> getCities() {
		try {
			return DatasCache.getCities();
		} catch (IOException e) {
			e.printStackTrace();
			return Collections.emptyList();
		}
	}
}